From c5835ff514b065d446f0ceb81f0528473728f8f6 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 8 Apr 2026 13:53:04 +0200 Subject: [PATCH] Prefer using g_clear_object/g_clear_pointer macro where possible Part-of: --- src/shell-mount-operation.c | 13 ++----------- src/st/st-icon.c | 15 ++++----------- src/st/st-scroll-bar.c | 16 +++------------- src/st/st-texture-cache.c | 15 ++++----------- src/st/st-theme-node.c | 31 ++++++------------------------- src/st/st-widget.c | 6 ++---- 6 files changed, 21 insertions(+), 75 deletions(-) diff --git a/src/shell-mount-operation.c b/src/shell-mount-operation.c index a318e554a..9089cf277 100644 --- a/src/shell-mount-operation.c +++ b/src/shell-mount-operation.c @@ -83,11 +83,7 @@ shell_mount_operation_show_processes (GMountOperation *operation, { ShellMountOperation *self = SHELL_MOUNT_OPERATION (operation); - if (self->pids != NULL) - { - g_array_unref (self->pids); - self->pids = NULL; - } + g_clear_pointer (&self->pids, g_array_unref); g_free (self->message); g_strfreev (self->choices); @@ -107,12 +103,7 @@ shell_mount_operation_finalize (GObject *obj) g_strfreev (self->choices); g_free (self->message); - - if (self->pids != NULL) - { - g_array_unref (self->pids); - self->pids = NULL; - } + g_clear_pointer (&self->pids, g_array_unref); G_OBJECT_CLASS (shell_mount_operation_parent_class)->finalize (obj); } diff --git a/src/st/st-icon.c b/src/st/st-icon.c index 546f620ca..d55ca419e 100644 --- a/src/st/st-icon.c +++ b/src/st/st-icon.c @@ -176,17 +176,12 @@ st_icon_dispose (GObject *gobject) { StIconPrivate *priv = ST_ICON (gobject)->priv; - if (priv->icon_texture) - { - clutter_actor_destroy (priv->icon_texture); - priv->icon_texture = NULL; - } + g_clear_pointer (&priv->icon_texture, clutter_actor_destroy); if (priv->pending_texture) { clutter_actor_destroy (priv->pending_texture); - g_object_unref (priv->pending_texture); - priv->pending_texture = NULL; + g_clear_object (&priv->pending_texture); } g_clear_signal_handler (&priv->icon_theme_changed_id, @@ -551,8 +546,7 @@ st_icon_update (StIcon *icon) if (priv->pending_texture) { clutter_actor_destroy (priv->pending_texture); - g_object_unref (priv->pending_texture); - priv->pending_texture = NULL; + g_clear_object (&priv->pending_texture); priv->opacity_handler_id = 0; } @@ -626,8 +620,7 @@ st_icon_update (StIcon *icon) } else if (priv->icon_texture) { - clutter_actor_destroy (priv->icon_texture); - priv->icon_texture = NULL; + g_clear_pointer (&priv->icon_texture, clutter_actor_destroy); } } diff --git a/src/st/st-scroll-bar.c b/src/st/st-scroll-bar.c index 056f9870c..9529d1795 100644 --- a/src/st/st-scroll-bar.c +++ b/src/st/st-scroll-bar.c @@ -187,17 +187,8 @@ st_scroll_bar_dispose (GObject *gobject) if (priv->adjustment) st_scroll_bar_set_adjustment (bar, NULL); - if (priv->handle) - { - clutter_actor_destroy (priv->handle); - priv->handle = NULL; - } - - if (priv->trough) - { - clutter_actor_destroy (priv->trough); - priv->trough = NULL; - } + g_clear_pointer (&priv->handle, clutter_actor_destroy); + g_clear_pointer (&priv->trough, clutter_actor_destroy); G_OBJECT_CLASS (st_scroll_bar_parent_class)->dispose (gobject); } @@ -965,8 +956,7 @@ st_scroll_bar_set_adjustment (StScrollBar *bar, g_signal_handlers_disconnect_by_func (priv->adjustment, on_changed, bar); - g_object_unref (priv->adjustment); - priv->adjustment = NULL; + g_clear_object (&priv->adjustment); } if (adjustment) diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c index a30ebfa56..daba9f6bb 100644 --- a/src/st/st-texture-cache.c +++ b/src/st/st-texture-cache.c @@ -301,17 +301,10 @@ texture_load_data_free (gpointer p) { AsyncTextureLoadData *data = p; - if (data->icon_info) - { - g_object_unref (data->icon_info); - if (data->colors) - st_icon_colors_unref (data->colors); - } - else if (data->file) - g_object_unref (data->file); - - if (data->key) - g_free (data->key); + g_clear_object (&data->icon_info); + g_clear_pointer (&data->colors, st_icon_colors_unref); + g_clear_object (&data->file); + g_clear_pointer (&data->key, g_free); if (data->actors) g_slist_free_full (data->actors, (GDestroyNotify) g_object_unref); diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c index 8fbb71a10..7cfea44b8 100644 --- a/src/st/st-theme-node.c +++ b/src/st/st-theme-node.c @@ -64,17 +64,12 @@ maybe_free_properties (StThemeNode *node) { if (node->properties) { - g_free (node->properties); - node->properties = NULL; + g_clear_pointer (&node->properties, g_free); node->n_properties = 0; } - if (node->inline_properties) - { - /* This destroys the list, not just the head of the list */ - cr_declaration_destroy (node->inline_properties); - node->inline_properties = NULL; - } + /* This destroys the list, not just the head of the list */ + g_clear_pointer (&node->inline_properties, cr_declaration_destroy); } static void @@ -82,23 +77,9 @@ st_theme_node_dispose (GObject *gobject) { StThemeNode *node = ST_THEME_NODE (gobject); - if (node->parent_node) - { - g_object_unref (node->parent_node); - node->parent_node = NULL; - } - - if (node->border_image) - { - g_object_unref (node->border_image); - node->border_image = NULL; - } - - if (node->icon_colors) - { - st_icon_colors_unref (node->icon_colors); - node->icon_colors = NULL; - } + g_clear_object (&node->parent_node); + g_clear_object (&node->border_image); + g_clear_pointer (&node->icon_colors, st_icon_colors_unref); st_theme_node_paint_state_free (&node->cached_state); diff --git a/src/st/st-widget.c b/src/st/st-widget.c index 226141ac2..983263f0e 100644 --- a/src/st/st-widget.c +++ b/src/st/st-widget.c @@ -257,8 +257,7 @@ st_widget_remove_transition (StWidget *widget) if (priv->transition_animation) { g_object_run_dispose (G_OBJECT (priv->transition_animation)); - g_object_unref (priv->transition_animation); - priv->transition_animation = NULL; + g_clear_object (&priv->transition_animation); } } @@ -2382,8 +2381,7 @@ st_widget_set_label_actor (StWidget *widget, if (priv->label_actor != label) { - if (priv->label_actor) - g_object_unref (priv->label_actor); + g_clear_object (&priv->label_actor); if (label != NULL) priv->label_actor = g_object_ref (label); -- 2.39.5